// import { ComputedRefImpl } from "@vue/reactivity";

// import { reactive } from "@vue/reactivity";
import { track, trigger } from "./baseHandles.js";
import { reactive } from "./reactive.spc.js";

export const ref = (val) => {
  if (isRef(val)) return val;
  return new RefImpl(val);
};
export const isRef = (val) => {
  return !!(val && val.__isRef);
};
const convert = (val) => {
  return isObject(val) ? reactive(val) : val;
};
const isObject = (val) => val !== null && typeof val === "object";
class RefImpl {
  constructor(val) {
    this.__isRef = true;
    this._val = convert(val);
  }
  get value() {
    track(this, "value");
    return this._val;
  }
  set value(val) {
    if (val !== this._val) {
      this._val = convert(val);
      trigger(this, "value");
    }
  }
}
// 直接使用对象语法的getter和setter
